﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using IotContract.Models;
using IotContract.Models.Clients;
using IotContract.Dtos.Servers;
using IotContract.Interfaces;
using IotContract.Dtos.Servers.Pushs;
using IotContract.Dtos.Clients.Equips;
using IotContract.Models.Webs;
using IotContract.Models.Process;
using IotContract.Models.Mqtt;
using XT.Common.Services;
using IotContract.Enums;
using IotContract.Configs;
using IotContract.Dtos.Remotes.Request;
using ProtoBuf.Grpc;

namespace IotContract.Grpcs
{
    [ServiceContract]
    public interface IConnectGrpcService: IGrpcCodeService
    {
        /// <summary>
        /// 获取url地址
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<AddressConfig>> GetUrlAddress();
        /// <summary>
        /// 请求连接命令
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<ClientStatusReturn>> ConnectCommand(ClientConnectCommand client);
        /// <summary>
        /// 状态命令
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<ClientStatusReturn>> StatusCommand(ClientStatusCommand client);
        /// <summary>
        /// 控制命令
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<string>> ControlCommand(ClientControlCommand control);

        /// <summary>
        /// 控制命令
        /// </summary>
        /// <param name="controls"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<string>> ControlCommands(List<ClientControlCommand> controls);
        /// <summary>
        /// 完成任务
        /// </summary>
        /// <param name="fmsJobCompleteRequest"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<string>> CompleteJob(FmsJobCompleteRequest fmsJobCompleteRequest);

        /// <summary>
        /// 添加写入命令
        /// </summary>
        /// <param name="commands"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<string>> AddWriteCommand(List<OperationWriteCommand> commands);
        /// <summary>
        /// 读取所有程序控制指令
        /// </summary>
        /// <param name="command"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        [OperationContract]
        IAsyncEnumerable<ClientControlCommand> ReadControlCommand(ClientControlCommand command, CallContext context = default);
        /// <summary>
        /// 请求设备数据命令
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<List<IotEquipDto>>> RequestEquipsCommand(ClientRequestCommand request);

        /// <summary>
        /// 请求推送的数据
        /// </summary>
        /// <param name="commands"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<List<PushEquipWeb>>> RequestPushEquips(List<ClientRequestCommand> commands);
        /// <summary>
        /// 请求服务端数据
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<List<PushEquipDto>>> RequestServerEquips(ClientRequestCommand command);
        /// <summary>
        /// 请求设备点位数据命令
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<List<EquipTagDto>>> RequestTagsCommand(ClientRequestCommand request);

        /// <summary>
        /// 推送设备
        /// </summary>
        /// <param name="equips"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [OperationContract]
        Task<List<OperationWriteCommand>> PushEquips(List<PushEquipDto> equips);

        /// <summary>
        /// 请求推送的点位
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<List<PushTagWeb>>> RequestPushTags(ClientRequestCommand command);

        /// <summary>
        /// 请求调度数据
        /// </summary>
        /// <param name="provider"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<List<ProcessBaseData>>> RequestProcessDatas(ProcessProviderCommand provider);

        /// <summary>
        /// 添加任务
        /// </summary>
        /// <returns>错误消息，为空成功</returns>
        [OperationContract]
        Task<GrpcReturn<string>> AddProcessJob(ProcessJobCommand command);

        /// <summary>
        /// 执行相关调度数据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<string>> ExecuteProcessData(ProcessJobCommand command);
        /// <summary>
        /// 移除任务
        /// </summary>
        /// <returns>错误消息，为空成功</returns>
        [OperationContract]
        Task<GrpcReturn<string>> RemoveProcessJob(ProcessJobCommand command);
        /// <summary>
        /// 添加Web控制
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<string>> AddWebControl(WebControlModel control);




        /// <summary>
        /// 请求Mqtt客户端数据
        /// </summary>
        /// <param name="provider"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<List<MqttClientInfo>>> RequestMqttClientInfos(MqttProviderCommand provider);


        

        /// <summary>
        /// 启停Mqtt服务器
        /// </summary>
        /// <param name="provider"></param>
        /// <returns></returns>
        [OperationContract]
        Task<GrpcReturn<MqttGrpcReturn>> StartOrStopMqttServer(MqttProviderCommand provider);
        [OperationContract]
        Task<GrpcReturn<MqttGrpcReturn>> RequestMqttServerStatus();
        [OperationContract]
        Task<GrpcReturn<MqttGrpcReturn>> StartOrStopMqttProcessData(MqttProviderCommand provider);
        [OperationContract]
        Task<GrpcReturn<MqttGrpcReturn>> GetDataPublishStatus();
        
    }
}
